<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2019-11-12
 * Time: 20:13
 */

namespace app\api\service;
use app\api\model\ProductOrder;
use app\api\service\order\ProductOrderSer;


class WxNotify extends \WxPayNotify
{
    public function NotifyProcess($objData, $config, &$msg)
    {
       if($objData['result_code'] == 'SUCCESS' && $objData['return_code'] == 'SUCCESS')
        {

            $outTradeNo = $objData['out_trade_no'];
            //获取通知的数据
            if (empty($outTradeNo)) {
                # 如果没有数据，直接返回失败
                return false;
            }
            /**
             * 根据订单类型进行操作
             */
            $outTradeNoArr = explode("s",$outTradeNo);
            $type = $outTradeNoArr[0];
            if($type == 1) {
                // 产品订单
                return $this->updateProductOrder($outTradeNo);
            }
        }
        else{
            return true;
        }
    }

    /**
     * 商城订单
     */
    private function updateProductOrder($outTradeNo)
    {
        $order = ProductOrder::where('out_trade_no',$outTradeNo)->find();
        $GoodsOrderSer = new ProductOrderSer($order);
        return $GoodsOrderSer->changeStatus();
    }
}